8. 数猫をGUIアプリにする(4)
https://gyazo.com/ec180c9998e89408128b8580bbfed322
code: suunekoai.py
from tkinter import Frame, Button
from suuneko import Suuneko
class Suunekoai(Suuneko):
def __init__(self, A, CellSize = 60):
super(Suunekoai, self).__init__(CellSize)
self.base112 = Frame(self.base11)
self.base112.pack()
for i in range(9):
for j in range(9):
if n:
self.change_status(i, j, n)
self.fill()
self.eraseButton = Button(self.base112, text = ' sweep ', command = self.sweep)
self.eraseButton.pack(side="left")
self.eraseButton = Button(self.base112, text = ' singleton ', command = self.singleton)
self.eraseButton.pack(side="left")
self.eraseButton = Button(self.base112, text = ' singular ', command = self.singular)
self.eraseButton.pack(side="left")
def seek(self, i, j):
def sweep(self):
for i in range(9):
for j in range(9):
if self.is_blank(i, j):
for n in self.seek(i, j):
if self.get_color(i, j, n) == 'grey50':
self.change_color(i, j, n, 'red')
def singleton(self):
for i in range(9):
for j in range(9):
if self.is_blank(i, j):
N = []
for n in range(1, 10):
if self.get_color(i, j, n) == 'grey50':
N.append(n)
if len(N) == 1:
self.change_color(i, j, N0, 'red') def singular(self):
def dic(area):
D = {}
for n in range(1, 10):
for i, j in area:
if self.exists(i, j, n):
if n in D:
else:
return D
for i0 in range(9):
D = dic(self.row(i0))
for n in D:
self.change_color(i, j, n, 'red')
for j0 in range(9):
D = dic(self.column(j0))
for n in D:
self.change_color(i, j, n, 'red')
for i0 in range(3):
for j0 in range(3):
D = dic(self.block(i0, j0))
for n in D:
self.change_color(i, j, n, 'red')
if __name__ == "__main__":
suuneko = Suunekoai(A)
suuneko.run()